package cn.source.enums;

import cn.source.common.exception.base.BaseException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author coderwaves
 * @date 2022/7/12 11:36
 */
@Getter
@AllArgsConstructor
public enum PayTypeEnum {
    /**
     * payType
     */
    ALI_PAY("AliPay","支付宝支付"),
    WX_JS_PAY("WXMpPay", "微信公众号"),
    WX_PAY("WXPay","微信支付"),
    WX_H5_PAY("WXH5Pay","微信H5支付");
    private String code;
    private String desc;

    public static List<String> types(){
        List<String> types = new ArrayList<>();
        for (PayTypeEnum value : PayTypeEnum.values()) {
            types.add(value.code);
        }
        return types;
    }

    public static PayTypeEnum getPayType(String code){
        for (PayTypeEnum value : PayTypeEnum.values()) {
            if(value.getCode().equals(code)){
                return value;
            }
        }
        throw new BaseException("500","支付方式错误");
    }
}
